package com.wangyukai.jmonitor.plugin;

import java.io.File;
import java.net.InetAddress;
import java.util.Arrays;

public class DiskPlugin implements IMonitorPlugin{
    @Override
    public String executeCheck() {
        File[] roots = File.listRoots();
        StringBuilder result = new StringBuilder();
        try {
            InetAddress ip = InetAddress.getLocalHost();
            result.append("服务器：" +ip);
        }catch (Exception ex){
            result.append("服务器：" );
        }
        result.append("\r\n");
        Arrays.stream(roots).forEach( file -> {

            if(file.getTotalSpace() > 0){

                result.append(file.getAbsolutePath()+": "+file.getFreeSpace()/(1024*1024*1024)+" GB, 剩余空间：");
                result.append( (float)file.getFreeSpace()/file.getTotalSpace());
            }

            result.append("\r\n");
        });

        return result.toString();
    }

    public static void main(String[] args) {
        DiskPlugin plugin = new DiskPlugin();
        System.out.println(plugin.executeCheck());
    }
}
